package com.neusoft.yiyang.medical.controller;

import com.neusoft.yiyang.common.entity.medical.MedicationOrderRecord;
import com.neusoft.yiyang.medical.service.MedicationOrderRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "药物医嘱执行记录接口", description = "管理药物医嘱的执行情况，记录用药时间、剂量、执行人等信息")
@RestController
@RequestMapping("/medication-order-record")
public class MedicationOrderRecordController {

    @Autowired
    private MedicationOrderRecordService medicationOrderRecordService;

    @Operation(summary = "创建药物医嘱执行记录", description = "记录药物医嘱的实际执行情况（含执行时间、剂量、执行人等）")
    @PostMapping("/create")
    public void createMedicationOrderRecord(
            @Parameter(description = "药物医嘱执行记录信息（含药物医嘱ID、执行详情等）", required = true)
            @RequestBody MedicationOrderRecord medicationOrderRecord) {
        medicationOrderRecordService.createMedicationOrderRecord(medicationOrderRecord);
    }

    @Operation(summary = "获取所有药物医嘱执行记录", description = "查询系统中所有药物医嘱的执行记录")
    @GetMapping("/all")
    public List<MedicationOrderRecord> getAllMedicationOrderRecords() {
        return medicationOrderRecordService.getAllMedicationOrderRecords();
    }

    @Operation(summary = "查询客户的药物医嘱执行记录", description = "获取指定客户的所有药物医嘱执行记录")
    @GetMapping("/customer/{customerId}")
    public List<MedicationOrderRecord> getMedicationOrderRecordsByCustomerId(
            @Parameter(description = "客户ID", required = true)
            @PathVariable Integer customerId) {
        return medicationOrderRecordService.getMedicationOrderRecordsByCustomerId(customerId);
    }

    @Operation(summary = "更新药物医嘱执行记录", description = "修改药物医嘱执行记录的信息（如补充执行备注、修正执行时间等）")
    @PutMapping("/update/{medicationOrderRecordId}")
    public void updateMedicationOrderRecord(
            @Parameter(description = "药物医嘱执行记录ID", required = true) @PathVariable Integer medicationOrderRecordId,
            @Parameter(description = "更新后的执行记录信息", required = true) @RequestBody MedicationOrderRecord medicationOrderRecord) {
        medicationOrderRecord.setMedicationOrderRecordId(medicationOrderRecordId);
        medicationOrderRecordService.updateMedicationOrderRecord(medicationOrderRecord);
    }

    @Operation(summary = "删除药物医嘱执行记录", description = "移除指定的药物医嘱执行记录")
    @DeleteMapping("/delete/{medicationOrderRecordId}")
    public void deleteMedicationOrderRecord(
            @Parameter(description = "药物医嘱执行记录ID", required = true) @PathVariable Integer medicationOrderRecordId) {
        medicationOrderRecordService.deleteMedicationOrderRecord(medicationOrderRecordId);
    }

    @Operation(summary = "查询客户的药品使用记录（含详情）", description = "获取指定客户的药物医嘱执行记录及关联的药品信息")
    @GetMapping("/getMedicationRecordByCutomerId/{customerId}")
    public List<Map<String, Object>> getMedicationRecordByCustomerId(
            @Parameter(description = "客户ID", required = true) @PathVariable Integer customerId) {
        return medicationOrderRecordService.getMedicationRecordByCustomerId(customerId);
    }

    @Operation(summary = "查询药物医嘱对应的执行记录", description = "根据药物医嘱ID获取其所有执行记录")
    @GetMapping("/getMedicationRecordByMedicationOrderId/{medicationOrderId}")
    public List<MedicationOrderRecord> getMedicationRecordByMedicationOrderId(
            @Parameter(description = "药物医嘱ID", required = true) @PathVariable Integer medicationOrderId) {
        return medicationOrderRecordService.getMedicationRecordByMedicationOrderId(medicationOrderId);
    }
}